package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.link.view.adapter.PickAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class TeamWorkTypePopWindow extends BasePopWindow {

    private FilterResultClick filterResultClick;
    private IItemClick iItemClick;
    private RecyclerView rv1;
    private PickAdapter mAdapter1;
    private int position1 = 0;

    public interface FilterResultClick {
        void result(PickSelectEntity... entity);
    }

    public interface PickingResultClick {
        void result(List<String> citysNo, List<String> typeNo, List<String> scaleNo, List<String> statusNo);

        void dimiss();
    }

    public void setFilterResultClick(FilterResultClick filterResultClick) {
        this.filterResultClick = filterResultClick;
    }

    public TeamWorkTypePopWindow(Context context) {
        super(context, DIR_RIGHT);
    }

    @Override
    protected int popLayout() {
        return R.layout.popup_team_work_type;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        setAnimationStyle(com.swgk.core.R.style.popwindow_down_up);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        TextView okView = holder.getPop().findViewById(R.id.ok_view);
        TextView reSetView = holder.getPop().findViewById(R.id.reset_view);
        rv1 = holder.getPop().findViewById(R.id.rv1);

        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (position1 >= 0) {
                    filterResultClick.result(
                            mAdapter1.getDatas().get(position1));
                } else {
                    filterResultClick.result();
                }
                dissMiss();
            }
        });

        reSetView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAdapter1.resetCheckDatas();
                mAdapter1.setDefItem(-1);
                position1 = -1;
                filterResultClick.result();
                dissMiss();
            }
        });

        mAdapter1 = new PickAdapter(mContext, null, R.layout.item_pick_filter_child);
        //pickAdapterCity.setMultiSelect(true);
        mAdapter1.setItemSelect(true);
        mAdapter1.setDefItem(-1);
        rv1.setLayoutManager(new GridLayoutManager(mContext, 4));
        rv1.setAdapter(mAdapter1);

        mAdapter1.setOnItemClick(new AdapterOnItemClick<PickSelectEntity>() {
            @Override
            public void onItemClick(PickSelectEntity pickSelectEntity, int position) {
                position1 = position;
                if (iItemClick != null) {
                    iItemClick.itemClick(pickSelectEntity.getNo(), position, pickSelectEntity.getProjectscale());
                }
            }
        });
    }

    public void setData1(List<PickSelectEntity> datas) {
        mAdapter1.setDatas(datas);
        mAdapter1.setDefItem(position1);
    }

    public int getPosition1() {
        return position1;
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    public interface IItemClick {
        void itemClick(String firstNo, int position, String name);
    }

    public void onItemClick(IItemClick iItemClick) {
        this.iItemClick = iItemClick;
    }
}
